﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Getting a summary of validation results</title>
  <keywords>
    <keyword translate="true">Validation</keyword>
    <keyword translate="true">ValidationContext</keyword>
    <keyword translate="true">ValidationSummary</keyword>
    <keyword translate="true">ValidationToViewModel</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Getting a summary of validation results</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Sometimes you just need to get a summary of all warnings and errors of an object. All validation is gathered in the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_IValidationContext" styleclass="Normal" translate="true">IValidationContext</link><text styleclass="Normal" translate="true"> and available on that class. However, there are some convenience classes that allow a developer to create a summary based on a specific tag. This convenience class is </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_IValidationSummary" styleclass="Normal" translate="true">IValidationSummary</link><text styleclass="Normal" translate="true">, which gathers the right information from an instance of </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_IValidationContext" styleclass="Normal" translate="true">IValidationContext</link><text styleclass="Normal" translate="true">.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Creating a summary of all validations</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">To retrieve a summary of all validations from a </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_IValidationContext" styleclass="Normal" translate="true">IValidationContext</link><text styleclass="Normal" translate="true">, use the following code:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">var</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">validationSummary</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">validationContext.GetValidationSummary();</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Creating a summary of all validations with a specific tag</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">To retrieve a summary of all validations with a specific tag from a </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_IValidationContext" styleclass="Normal" translate="true">IValidationContext</link><text styleclass="Normal" translate="true">, use the following code:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">var</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">validationSummary</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">validationContext.GetValidationSummary(&quot;tag&quot;);</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Using the ValidationToViewModel attribute</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_MVVM_ValidationToViewModelAttribute" styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">ValidationToViewModel</link><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> attribute allows a developer to gather a summary of an object easily. For example, to get all the person related validation into the </text><text styleclass="Normal" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">PersonValidationSummary</text><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> property, use the property definition below:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">[ValidationToViewModel(Tag</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">&quot;PersonValidation&quot;)]</text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">IValidationSummary</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">PersonValidationSummary</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">{</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">get;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">set;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">}</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">All validation results that have the tag </text><text styleclass="Normal" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">PersonValidation</text><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> will automatically be gathered into the </text><text styleclass="Normal" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">PersonValidationSummary</text><text styleclass="Normal" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> property after each validation sequence.</text></para>
  </body>
</topic>
